<template>
  <div class="main-container">
    <div class="breadcrumb">
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item>工艺路线管理</el-breadcrumb-item>
        <el-breadcrumb-item>工艺审批</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <el-form inline :model="queryProductionFilters">
      <div class="search-left">
        <el-form-item>
          <el-input v-model="queryProductionFilters.drawingNumber" class="w150" placeholder="输入图号" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-input v-model="queryProductionFilters.productName" class="w150" placeholder="产品名称" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-select v-model="queryProductionFilters.state" class="w150" placeholder="状态" filterable clearable>
            <template v-for="item in stateList">
              <el-option :label="item" :value="item" :key="item"></el-option>
            </template>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select v-model="queryProductionFilters.type" class="w150" placeholder="类型" clearable filterable>
            <el-option label="返修" value="返修"></el-option>
            <el-option label="生产" value="生产"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-input v-model="queryProductionFilters.noticeNumber" class="w150" placeholder="通知单号" clearable></el-input>
        </el-form-item>
        <el-button @click="clear()">重置</el-button>
        <el-button type="primary" @click="queryProduction()">查询</el-button>
      </div>
    </el-form>

    <el-table border stripe :data="firstData" row-key="id" height="650" @row-dblclick="showDesignProcessDetail">
      <el-table-column type="index" label="序号" align="center" width="50"></el-table-column>
      <el-table-column prop="state" label="状态" align="center" width="120"></el-table-column>
      <el-table-column prop="workingNumber" label="产品工号" align="center" width="100"></el-table-column>
      <el-table-column prop="noticeNumber" label="通知单号" align="center" width="100"></el-table-column>
      <el-table-column prop="drawingNumber" label="图号" align="center" width="125"></el-table-column>
      <el-table-column prop="sequenceId" label="序列号" align="center" width="70"></el-table-column>
      <el-table-column prop="productName" label="品名" align="center" width="150"></el-table-column>
      <el-table-column prop="materialQuality" label="材质" align="center" width="150"></el-table-column>
      <el-table-column prop="number" label="数量" align="center" width="75"></el-table-column>
      <el-table-column prop="deliveryDate" label="交货日期" sortable align="center" width="120"></el-table-column>
      <el-table-column prop="typeProduction" label="类型" align="center" width="75"></el-table-column>
      <el-table-column prop="remark" label="备注" align="center" min-width="120"></el-table-column>
      <el-table-column label="操作" width="150" fixed="right" align="center" v-if="$checkAuth('工艺路线投产审批')">
        <template slot-scope="scope">
          <el-button size="mini" type="primary" @click="onClickAudit(scope.row)" v-if="$checkAuth('工艺路线投产审批') && canAudit.includes(scope.row.state)">审批</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="queryProductionFilters.page"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="queryProductionFilters.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="totalNumberIndex"
      background
      class="mt10"
    >
    </el-pagination>
  </div>
</template>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
import { namespace } from 'vuex-class'
import Layout from '@/views/_common/Layout.vue'
import _ from 'lodash'

const vuexLogin = namespace('Login')
const vuexProcess = namespace('TwoProcess')

@Component({
  components: {
    Layout
  }
})
export default class Index extends Vue {
  @vuexLogin.State DesignReviewShow: any
  @vuexProcess.Action GET_PROCESS_INDEX: any
  @vuexProcess.State firstData: any
  @vuexProcess.State totalNumberIndex: any
  @vuexProcess.Action GET_PROCESS_DETAIL: any

  stateList: String[] = ['生产通知审批', '工艺设计', '工艺审批', '待派工', '生产中', '已完成', '生产通知变更', '工艺变更设计', '工艺变更审批']
  canAudit: any[] = ['工艺审批', '工艺变更审批']
  canDesignState: any[] = ['工艺设计', '待派工', '生产中', '工艺设计变更']
  // 查询条件
  queryProductionFilters: any = {
    drawingNumber: '',
    productName: '',
    noticeNumber: '',
    remark: '',
    state: '工艺审批',
    type: '',
    page: 1,
    pageSize: 20
  }

  /**
   * 页面初始化查询
   */
  created() {
    this.GET_PROCESS_INDEX({ ...this.queryProductionFilters })
  }

  /**
   * 查询产品记录
   */
  queryProduction() {
    this.GET_PROCESS_INDEX({ ...this.queryProductionFilters })
  }

  /**
   * 清空重置查询条件
   */
  clear() {
    this.queryProductionFilters = {
      drawingNumber: '',
      productName: '',
      noticeNumber: '',
      state: '工艺审批',
      remark: '',
      type: '',
      page: 1,
      pageSize: 20
    }
    this.queryProduction()
  }

  /**
   * 双击查看设计工艺版本详情
   */
  showDesignProcessDetail(row) {
    console.log(row.noticeId)

    this.getProcessDetail(row)
  }
  async getProcessDetail(row) {
    console.log('审核', row)
    let result = await this.GET_PROCESS_DETAIL({ producingId: row.producingId })
    if (result) {
      this.$router.push({
        name: 'process-review',
        params: {
          from: 'row',
          drawingNumber: row.drawingNumber,
          productName: row.productName,
          number: row.number,
          materialQuality: row.materialQuality,
          producingId: row.producingId,
          remark: row.remark
        }
      })
    }
  }

  /**
   * 点击审核按钮查看设计工艺版本详情
   */
  async onClickAudit(row) {
    console.log('审核', row)
    let result = await this.GET_PROCESS_DETAIL({ producingId: row.producingId, approved: false })
    if (result) {
      this.$router.push({
        name: 'process-review',
        params: {
          from: 'button',
          drawingNumber: row.drawingNumber,
          productName: row.productName,
          number: row.number,
          materialQuality: row.materialQuality,
          producingId: row.producingId,
          remark: row.remark
        }
      })
    }
  }

  /**
   * 工艺设计
   */
  onClickDesign(product) {
    let tempProduct = {
      producingId: product.producingId,
      drawingNumber: product.drawingNumber,
      productName: product.productName,
      materialQuality: product.materialQuality,
      number: product.number
    }
    this.$store.commit('TwoProcess/SET_PRODUCT_ON_DESIGN_VERSION', tempProduct)
    // 跳转至工艺设计页面
    this.$router.push({ name: 'design' })
  }

  /**
   * 分页功能
   */
  handleSizeChange(newSize) {
    this.queryProductionFilters.pageSize = newSize
    this.queryProduction()
  }
  handleCurrentChange(newPage) {
    this.queryProductionFilters.page = newPage
    this.queryProduction()
  }
}
</script>

<style lang="scss" scoped>
.total {
  float: left;
  // display: inline;
  border: 1px solid #ccc;
  margin-right: 30px;
  .total_title {
    width: 200px;
    color: #000;
    height: 260px;
    line-height: 30px;
    text-align: center;
    .text {
      font-size: 18px;
      font-weight: bold;
      margin: 0 5px;
    }
  }

  &:hover {
    color: #000;
    background: #fff;
  }
}
.s1 {
  display: none;
}
.s2 {
  height: 100px;
  display: none;
}
.breadcrumb {
  height: 25px;
  width: 100%;
  border: none;
}
//通知单滚动
.notice-box {
  display: -webkit-box;
  overflow-x: auto;
  /*适应苹果*/
  -webkit-overflow-scrolling: touch;
}

.notice-item {
  height: 270px;
}

/*隐藏掉滚动条*/
.notice-box::-webkit-scrollbar {
  display: none;
}

.layout .operation {
  overflow-x: auto;
}
.el-tabs {
  padding: 0 20px;
  margin: 0px 10px 0;
  border: 1px solid #e4e7ed;
  background-color: #fff;
  .el-tabs__content {
    min-width: 1200px;
  }
}
</style>